
/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
import Model.M_Pro;
import java.io.IOException;
import java.io.PrintWriter;
import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 *
 * @author thuydao
 */
@WebServlet(urlPatterns = {"/C_Pro_Account"})
public class C_Pro_Account extends HttpServlet {

    /**
     * Processes requests for both HTTP <code>GET</code> and <code>POST</code>
     * methods.
     *
     * @param request servlet request
     * @param response servlet response
     * @throws ServletException if a servlet-specific error occurs
     * @throws IOException if an I/O error occurs
     */
    protected void processRequest(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        response.setContentType("text/html;charset=UTF-8");
        PrintWriter out = response.getWriter();
        try {
            /* TODO output your page here. You may use following sample code. */
            out.println("<!DOCTYPE html>");
            out.println("<html>");
            out.println("<head>");
            out.println("<title>Servlet C_Pro</title>");            
            out.println("</head>");
            out.println("<body>");
            
            String action = request.getParameter("ProAction");
            if(action.equals("ShowDMSP"))
            {
                String dmsp = request.getParameter("dmsp");
                //out.println(dmsp);
                M_Pro pro = new M_Pro();
                M_Pro[] result = pro.showDMSP(dmsp);
              
                request.setAttribute("INFOPro", result);
                RequestDispatcher rd = request.getRequestDispatcher("Show_Pro.jsp");
                rd.forward(request, response);
                
            }
            if(action.equals("Giaban"))
            {
                String gia = request.getParameter("gia");
                M_Pro pro = new M_Pro();
                M_Pro[] result=null;
                if(gia.equals("duoi50"))
                    result = pro.showDuoi50();
                else if(gia.equals("tren150"))
                    result = pro.showTren150();
                else
                    result = pro.show50150();
                
                request.setAttribute("INFOPro", result);
                RequestDispatcher rd = request.getRequestDispatcher("Show_Pro.jsp");
                rd.forward(request, response);
            }
            
            /*if(action.equals("detail"))
            {
                String masp = request.getParameter("masp");
                M_Pro pro = new M_Pro();
                M_Pro[] result = pro.Search_Pro(masp);
                request.setAttribute("INFOPro_Detail", result);
                RequestDispatcher rd = request.getRequestDispatcher("Info_Pro.jsp");
                rd.forward(request, response);
            }
            else if(action.equals("ShowDMSP"))
            {
                String dmsp = request.getParameter("dmsp");
                M_Pro pro = new M_Pro();
                M_Pro[] result = pro.Search_Pro(dmsp);
                request.setAttribute("INFOPro_DMSP", result);
                
                if(dmsp.equals("HMLD"){
                RequestDispatcher rd = request.getRequestDispatcher("Pro_HMLamDep.jsp");
                rd.forward(request, response);
                }
                else if(dmsp.equals("BHM"))
                {
                RequestDispatcher rd = request.getRequestDispatcher("Pro_BepHM.jsp");
                rd.forward(request, response);
                }
                else {
                    RequestDispatcher rd = request.getRequestDispatcher("Pro_QuaTangHM.jsp");
                    rd.forward(request, response);
                }
            }*/
            
            
            out.println("</body>");
            out.println("</html>");
        } finally {
            out.close();
        }
    }

    // <editor-fold defaultstate="collapsed" desc="HttpServlet methods. Click on the + sign on the left to edit the code.">
    /**
     * Handles the HTTP <code>GET</code> method.
     *
     * @param request servlet request
     * @param response servlet response
     * @throws ServletException if a servlet-specific error occurs
     * @throws IOException if an I/O error occurs
     */
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        processRequest(request, response);
    }

    /**
     * Handles the HTTP <code>POST</code> method.
     *
     * @param request servlet request
     * @param response servlet response
     * @throws ServletException if a servlet-specific error occurs
     * @throws IOException if an I/O error occurs
     */
    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        processRequest(request, response);
    }

    /**
     * Returns a short description of the servlet.
     *
     * @return a String containing servlet description
     */
    @Override
    public String getServletInfo() {
        return "Short description";
    }// </editor-fold>

}
